﻿@model OA.Model.MyDelegation
@{
    string title = "新增工作委托";
    ViewBag.Title = title;
    Layout = "~/Areas/Member/Views/Shared/_form_layout.cshtml";
    string msg = ViewBag.Msg;
    string tips = string.Empty;
    if (!string.IsNullOrWhiteSpace(msg))
    {
        tips = $"layer.msg('{msg}');";
    }
    List<SelectListItem> listCustomForm = ViewBag.CustomFormList;
}
<style type="text/css">
   .layui-form-autocomplete dl dd{text-align:left;display:block;}
</style>
<div class="layui-form layui-tab-content" id="LAY_ucm" style="padding:0px">
    @using (Html.BeginForm(FormMethod.Post, htmlAttributes: new { @class = "layui-form", id = "myForm" }))
    {
        @Html.AntiForgeryToken()
        <div class="layui-form-item">
            <label class="layui-form-label">委托时间</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" lay-verify="required" name="RangeDateTime" id="RangeDateTime" placeholder="开始 到 结束" value="@Model.StartTime 到 @Model.EndTime">
            </div>
        </div>

        <div class="layui-form-item">
            @Html.LabelFor(model => model.ToEmpID, new { @class = "layui-form-label" })
            <div class="layui-input-block">
                @Html.HiddenFor(model => model.ID)
                <input data-val="true" id="ToEmpID" name="ToEmpID" type="hidden" value="@Model.ToEmpID">
                <input type="text" placeholder="请输入受托人员姓名" lay-verify="required" class="layui-input autocomplete" value="@Model.ToEmpName">
            </div>
        </div>



        <div class="layui-form-item">
            @Html.LabelFor(model => model.CustomFormID, new { @class = "layui-form-label" })
            <div class="layui-input-block">
                @foreach (var item in listCustomForm)
                {
                    <input type="checkbox" name="CustomFormID" title="@item.Text" value="@item.Value" lay-skin="primary">
                }
            </div>
        </div>

        <div class="layui-form-item" style="margin-top:12px;">
            <div class="layui-input-block">
                <input type="button" value="提 交" class="layui-btn mySubmit" />
            </div>
        </div>
    }
</div>
<script type="text/javascript">

    layui.use(['form', 'layedit', 'autocomplete', 'element', 'layer','laydate'], function () {
		form = layui.form;
        layer = layui.layer;
        element = layui.element;
        laydate = layui.laydate;
        autocomplete = layui.autocomplete;
        autocomplete.render({
            elem: $('.autocomplete'),
            url: '/Member/Home/GetEmployees',
            cache: false,
            template_val: '{{d.n}}',
            template_txt: '{{d.n}} <span class=\'layui-badge layui-bg-gray\'>{{d.d}}&nbsp;{{d.s}}&nbsp;{{d.n}}</span>',
            onselect: function (resp) {
                console.log(resp);
                $("#ToEmpID").val(resp.i);
            }
        });
        @Html.Raw(tips)
        laydate.render({
            elem: '#RangeDateTime'
            , type: 'datetime'
            , range: '到'
            , format: 'yyyy-MM-dd HH:mm:ss'
            , min:0
        });
    });
    var myFrom = $("#myForm");
    $(".mySubmit").click(function () {
        if ($.trim($("#ToEmpID").val()).length == 0) {
            layer.msg("请选择委托人", {
                icon: 5,
                shift: 6
            });
            return false;
        }
        var arr = new Array();
        $("input:checkbox[name=CustomFormID]:checked").each(function () {
            arr.push($(this).val());
        });
        if (arr.length == 0) {
            layer.msg("请至少选择一个委托单据", {
                icon: 5,
                shift: 6
            });
            return false;
        }
        $(".mySubmit").prop("disabled", true);
        var index = layer.load(1, {
            shade: [0.1, '#fff']
        });
        var myFrom = $("#myForm");
        $.post(myFrom.prop("action"), myFrom.serialize(), function (result) {
            $(".mySubmit").prop("disabled", false);
            layer.closeAll();
            if (result.State == 400) {
                layer.msg(data.Msg);
                return;
            }
            if (result.State == 402) {
                layer.msg(data.Msg);
                return;
            }
            else {
                layer.msg(result.Msg);
                window.parent.RefreshResultList();
            }
        });
        return false;
    });


</script>
